class CodeIssueDpd
  include DailyProjectDetails
  attr_reader :project, :name
  
  def initialize(document)
    @name = 'CodeIssue'
    @document = document
    @data = Array.new
    parse_document
  end
  
  def parse_document
    #[1] Get the project that this dpd is associated with.
    REXML::XPath.each(@document, '/' + @name + "DailyProjectData") do |e|
      @project = "#{e.attributes['Project']}"
    end
    
    #[2] Get the CodeIssue data associated with the project.
    REXML::XPath.each(@document, '/' + @name + "DailyProjectData/CodeIssueData") do |e|
      tool = "#{e.attributes['Tool']}"
      type = "#{e.attributes['IssueType']}"
      issueCount = "#{e.attributes['NumIssues']}"
      
      data = SensorData.new
      data.add_mapping('Tool', tool)
      data.add_mapping('IssueType', type)
      data.add_mapping('NumIssues', issueCount)
      @data.push(data)
    end
  end
  
  def get_tool_to_count
    total_issues = 0 
    tool_to_count = Hash.new 
    for tool in self.get_tools 
      current_count = 0 
      for data in self.get_data(tool) 
        issue_count = String.new(data.get_value('NumIssues')).to_i 
        current_count += issue_count 
        total_issues += issue_count 
      end 
      if current_count != 0
        tool_to_count[tool] = current_count
      end
    end
    return tool_to_count
  end
end
